package tag;

import java.util.Map;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

import by.grsu.hdm.media.Track;

/**
 * Class BorwseTag
 * 
 * @author Ryzhko
 * 
 */

public class BrowseTag extends TagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int counter = 0;
	private Map<String, Track> tracks = null;


	public int doStartTag() {
		tracks = (Map<String, Track>) pageContext.getAttribute("tracks");
		return EVAL_BODY_INCLUDE;
	}

	public int doAfterBody() throws JspException {
		try {

			// List tracks

			for (Track track : tracks.values()) {
				pageContext.getOut().println("<tr>");
				pageContext.getOut().println(
						"<input type=radio name=track value=" + track.getName()
								+ ">" + track.getName());
				pageContext.getOut().println("</tr>");
				counter++;
			}
			pageContext.getOut().println("<tr>");
			pageContext.getOut().println("<td>");

			pageContext.getOut().print(
					"<input type=submit name=button value=play>");
			pageContext.getOut().print(
					"<input type=submit name=button value=pause>");
			pageContext.getOut().print(
					"<input type=submit name=button value=stop>");
			pageContext.getOut().println("</td>");
			pageContext.getOut().println("</tr>");

		} catch (Exception e) {
			throw new JspException(e.toString());
		}
		if (counter >= tracks.size()) {
			counter = 0;
			return SKIP_BODY;
		}
		return SKIP_BODY;
	}
}